import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';
import 'package:get/get.dart';
import 'package:leader_help/utils/ifly/ifly_dialog.dart';
import 'package:leader_help/page/home/models/add_point.dart';
import 'package:leader_help/utils/component/list/section.dart';
import 'package:leader_help/utils/ifly/ifly_util.dart';
import 'package:leader_help/utils/ifly/xf_api_utils.dart';

import 'index.dart';
import 'widgets/widgets.dart';

class AddPointController extends GetxController {
  AddPointController();

  final state = AddPointState();

  void actionAdd() {
    state.items.add(AddPointModel());
    update();
  }

  void actionSure() {
    Get.back();
  }

  void actionDel(AddPointModel mod) {
    state.items.remove(mod);
    update();
  }

  showPickDialog(int index) async {
    var mod = state.items[index];
    await ifly_audio(textCtrl: mod.textCtrl);
  }

  /// 在 widget 内存中分配后立即调用。
  @override
  void onInit() {
    super.onInit();
    state.items = [AddPointModel()];
    state.list = [
      SectionModel(
          index: 0,
          itemBuilder: (ctx, index) {
            var mod = state.items[index];
            return AddPointCell(
              index: index,
              mod: mod,
            );
          },
          items: state.items)
    ];
  }

  /// 在 onInit() 之后调用 1 帧。这是进入的理想场所
  @override
  void onReady() {
    super.onReady();
  }

  /// 在 [onDelete] 方法之前调用。
  @override
  void onClose() {
    super.onClose();
  }

  /// dispose 释放内存
  @override
  void dispose() {
    super.dispose();
  }
}
